package com.leetcode;

import com.leetcode.common.TreeNode;

/**
 * 112. 路径总和
 *
 * @author fy
 * @date 2022-04-17 22:56
 */
public class Solution112 {

    public boolean hasPathSum(TreeNode root, int targetSum) {
        if (root == null) {
            return false;
        }
        if (root.left == null && root.right == null && root.val == targetSum) {
            return true;
        }
        return hasPathSum(root.left, targetSum - root.val) ||
                hasPathSum(root.right, targetSum - root.val);
    }

}
